// import {fetchPromise}  from './fetch.js'
// fetchPromise(`check-update-pgyer`)


export const formInline = reactive({
  user: '',
  region: '',
  date: '',
})
export const keyInfo = ref({
  apiKey: '922f5cea636ff981d00fa83b29af25b2',
  userKey: '2d9876416e67f7e4904bb87a9381c79f'
})
export const cosToken = ref({
  endpoint: '',
  key: '',
  params: {
    'key': '',
    'signature': '',
    'x-cos-security-token': '',
  },
})

export const getCOSToken = () =>{
  Axios({
    method: 'post',
    url: 'https://www.pgyer.com/apiv2/app/getCOSToken',
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    data:{
      _api_key:"922f5cea636ff981d00fa83b29af25b2",
      buildType:"ios"
    }
  })
  .then((res) => {
    const resData = res.data.data
    cosToken.value = resData
    console.log('getCOSToken', resData)
    appView(resData)
    buildsList(resData.key)
    // response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
  });
  }
  // 列出用户的App分组
export const appGroupListAll = (key) => {
  console.log('appView',key)
  Axios({
    method: 'post',
    url: 'https://www.pgyer.com/apiv2/appGroup/listAll',
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    data:{
      _api_key:keyInfo.value.apiKey
    }
  })
  .then((res) => {
    const accessToken = res.data
    // response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
  });
}

  // 查看自己上传的应用
export const appListMy = (key) => {
  console.log('appView',key)
  Axios({
    method: 'post',
    url: 'https://www.pgyer.com/apiv2/app/listMy',
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    data:{
      _api_key:keyInfo.value.apiKey,key,
      page:1
    }
  })
  .then((res) => {
    console.log('appListMy', res.data.data)
    appList.value = res.data.data.list
    // response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
  });
}
export const appView = (key) => {
  console.log('appView',key)
  Axios({
    method: 'post',
    url: 'https://www.pgyer.com/apiv2/app/view',
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    data:{
      _api_key:"922f5cea636ff981d00fa83b29af25b2",
      appKey:'60b108955d736a29b2a1ec3a79974e24',
      buildType:1 // 应用类型（1:iOS; 2:Android）
    }
  })
  .then((res) => {
    const accessToken = res.data
    // response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
  });
}
export const buildsList = (key) => {
  console.log('cosToken', cosToken.value)
  console.log('buildsList',key)
  Axios({
    method: 'post',
    url: 'https://www.pgyer.com/apiv2/app/builds',
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    data:{
      _api_key:"922f5cea636ff981d00fa83b29af25b2",
      appKey:'adcef6a3afa3e2417a92222178841841',
      buildType:1 // 应用类型（1:iOS; 2:Android）
    }
  })
  .then((res) => {
    const accessToken = res.data
    // response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
  });
}
export const uploadApp = (key) => {
  console.log('buildsList',key)
  Axios({
    method: 'post',
    url: 'https://www.pgyer.com/apiv2/app/upload',
    headers: {'Content-Type': 'multipart/form-data'},
    data:{
      _api_key:"922f5cea636ff981d00fa83b29af25b2",
      file:'adcef6a3afa3e2417a92222178841841'
    }
  })
  .then((res) => {
    const accessToken = res.data
    // response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
  });
}

  console.log('onMounted', new Date())
  getCOSToken()
  appListMy()

